<template>
	<view>

		<view class="m-list">
			<view class="m-item" v-for="(item,index) in list" :key="index">
				<view class="m-item-top">
					<view class="m-item-top__left">
						<text>订单号：{{item.order_id}}</text>
					</view>
					<view class="m-item-top__right">
						<text>已完成</text>
					</view>
				</view>
				<view class="goods">
					<view class="goods-image">
						<image :src="item.level.logo" mode="aspectFill"></image>
					</view>
					<view class="goods-content">
						<view class="goods-name u-line-1">
							<text>{{item.level.title}}</text>
						</view>
						<view class="goods-spec">
							<!-- <text>有效期1年</text> -->
						</view>
						<view class="goods-bottom">
							<view class="goods-num">
								<text>x1</text>
							</view>
							<view class="">
								<text class="goods-price">{{item.level.price}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="m-item-bottom">
					<view class="m-item-bottom__left">
						<view class="">
							<text>下单时间：{{item.dtTime}}</text>
						</view>
						<view class="">
							<text>订单金额：￥{{item.level.price}}</text>
						</view>
					</view>
				</view>
			</view>

			<view class="m-empty" v-if="loading == 'noMore' && list.length ==0">
				<image src="../static/hotel/m-hotel-empty.png" mode=""></image>
				<view class="m-empty-text">
					<text>暂无会员购买记录</text>
				</view>
			</view>
			<uni-load-more :status="loading" v-else></uni-load-more>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				levelBack:[],
				list:[],
				loading:'loading',
				params:{
					page:1,
					pagenum:10,
				}
			}
		},
		onReachBottom() {
			if(this.loading == 'loading' || this.loading == 'noMore') return false;
			this.getListFun()
		},
		onLoad() {
			this.getIndexFun()
		},
		methods: {
			clickTabFun(item, index) {
				this.currentTab = index
			},
			getIndexFun(){
				this.$http.getJson('index_index').then(res=>{
					if(res.code == 1){
						this.levelBack = []
						res.data.adverts.forEach(item=>{
							if(item.title == '会员等级logo'){
								this.levelBack = item.images
							}
						})
						this.getListFun()
					}
				})
			},
			getListFun(){
				let params = this.params
				this.loading = 'loading'
				this.$http.getJson('money_vipLogs',params).then(res=>{
					if(res.code == 1){
						let data = res.data || []
						let len = data.length
						if(len > 0){
							data.forEach(item=>{
								let val = this.levelBack.find(val=>val.title == item.level.title)
								if(val){
									item.level['logo'] = val.image
								}
							})
							this.list= this.list.concat(data)
						}
						if(len == params.limit){
							this.params.page += 1
							this.loading = 'more'
						}else{
							this.loading = 'noMore'
						}
					}else{
						this.$m.msg(res.msg)
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f6f6f6;
	}


	.m-list {
		padding-top: 20rpx;

		.m-item {
			background: #fff;
			padding: 0 25rpx;
			margin-bottom: 20rpx;

			.m-item-top {
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0; 

				.m-item-top__left {
					font-size: 24rpx;
					color: #34302D;
				}

				.m-item-top__right {
					font-size: 24rpx;
					color: #D3A358;
				}
			}

			.m-item-bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding-top: 23rpx;
				padding-bottom: 23rpx;
				border-top: 1px solid #E6E3DE;

				.m-item-bottom__left {
					font-size: 24rpx;
					color: #75706A;
					line-height: 36rpx;
				}

				.m-item-bottom__right {
					display: flex;
					align-items: center;

					.m-item-btn {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 136rpx;
						height: 48rpx;
						background: #FFFFFF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						border: 2rpx solid #D3A358;
						font-size: 24rpx;
						color: #D3A358;
						margin-left: 20rpx;
					}

					.m-item-btn__extend {
						background: #D3A358;
						color: #fff;
					}

					.m-item-btn__cancel {
						border-color: #E6E3DE;
						color: #75706A;
					}
				}
			}
		}
	}
	
	.goods{
		display: flex;
		padding: 20rpx 0;
		border-top: 1px solid #E6E3DE;
		.goods-image{
			width: 140rpx;
			height: 140rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.goods-content{
			width: 540rpx;
			margin-left: 20rpx;
			.goods-name{
				font-size: 28rpx;
				color: #34302D;
				line-height: 40rpx;
				font-weight: 800;
				margin-top: 4rpx;
			}
			.goods-spec{
				font-size: 24rpx;
				color: #9A958F;
				margin-top: 8rpx;
				height: 33rpx;
				line-height: 33rpx;
			}
			.goods-bottom{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.goods-num{
					font-size: 24rpx;
					color: #9A958F;
				}
				.goods-price{
					font-size: 40rpx;
					color: #DE2C38;
					&::before{
						content: '￥';
						font-size: 24rpx;
					}
				}
			}
		}
	}

	.m-empty {
		display: flex;
		flex-direction: column;
		text-align: center;
		align-items: center;
		font-size: 26rpx;
		color: #ADAAA5;
		padding-top: 150rpx;

		image {
			width: 320rpx;
			height: 260rpx;
			margin-bottom: 30rpx;
		}
	}
</style>